<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电影天堂 - 精选电影列表</title>
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;500;700&display=swap" rel="stylesheet">
    <style>
        :root {
            --primary: #8e44ad;
            --primary-dark: #6c3483;
            --secondary: #3498db;
            --accent: #e74c3c;
            --light: #f8f9fa;
            --dark: #2c3e50;
            --card-bg: #ffffff;
            --card-shadow: rgba(0, 0, 0, 0.1);
            --success: #27ae60;
            --warning: #f39c12;
            --info: #2980b9;
            --gold: #ffd700;
        }
        
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }
        
        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #e4e7f1 100%);
            background-attachment: fixed;
            background-size: cover;
            color: var(--dark);
            font-family: 'Noto Sans SC', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
            min-height: 100vh;
            padding-bottom: 50px;
            line-height: 1.6;
        }
        
        .container {
            max-width: 1200px;
        }
        
        /* 搜索栏样式 */
        .search-container {
            margin: 20px auto 30px;
            max-width: 700px;
            position: relative;
        }
        
        .search-box {
            background: rgba(255, 255, 255, 0.9);
            backdrop-filter: blur(10px);
            border-radius: 50px;
            padding: 15px 25px;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.15);
            display: flex;
            align-items: center;
            border: 2px solid rgba(142, 68, 173, 0.3);
            transition: all 0.3s ease;
        }
        
        .search-box:focus-within {
            background: rgba(255, 255, 255, 1);
            border-color: var(--primary);
            box-shadow: 0 8px 25px rgba(142, 68, 173, 0.25);
        }
        
        .search-box i {
            font-size: 1.5rem;
            color: var(--primary);
            margin-right: 15px;
            opacity: 0.8;
        }
        
        #searchInput {
            background: transparent;
            border: none;
            color: var(--dark);
            font-size: 1.1rem;
            width: 100%;
            padding: 8px 0;
            outline: none;
            font-weight: 500;
        }
        
        #searchInput::placeholder {
            color: rgba(44, 62, 80, 0.7);
        }
        
        .page-header {
            text-align: center;
            margin: 30px 0 40px;
            padding: 20px 0;
            position: relative;
        }
        
        .page-header h1 {
            font-size: 3.5rem;
            font-weight: 800;
            text-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);
            letter-spacing: 1px;
            margin-bottom: 15px;
            position: relative;
            display: inline-block;
            background: linear-gradient(to right, var(--primary), var(--secondary));
            -webkit-background-clip: text;
            background-clip: text;
            color: transparent;
            background-size: 200% auto;
            animation: shine 3s linear infinite;
        }
        
        @keyframes shine {
            to {
                background-position: 200% center;
            }
        }
        
        .page-header h1:after {
            content: '';
            position: absolute;
            bottom: -10px;
            left: 50%;
            transform: translateX(-50%);
            width: 120px;
            height: 5px;
            background: linear-gradient(to right, var(--primary), var(--accent));
            border-radius: 3px;
        }
        
        .page-header p {
            font-size: 1.2rem;
            max-width: 700px;
            margin: 0 auto;
            opacity: 0.7;
            color: var(--dark);
        }
        
        .movie-card {
            background: var(--card-bg);
            border-radius: 15px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
            height: 100%;
            display: flex;
            flex-direction: column;
            border: none;
            position: relative;
            transform: translateY(0);
            border-top: 4px solid var(--primary);
        }
        
        .movie-card:hover {
            transform: translateY(-10px) scale(1.02);
            box-shadow: 0 15px 35px rgba(0, 0, 0, 0.15);
        }
        
        .poster-container {
            position: relative;
            height: 380px;
            overflow: hidden;
        }
        
        .movie-poster {
            width: 100%;
            height: 100%;
            object-fit: cover;
            transition: transform 0.5s ease;
        }
        
        .movie-card:hover .movie-poster {
            transform: scale(1.08);
        }
        
        .card-body {
            padding: 25px;
            display: flex;
            flex-direction: column;
            flex-grow: 1;
        }
        
        .card-title {
            font-size: 1.5rem;
            font-weight: 700;
            color: var(--primary-dark);
            margin-bottom: 15px;
            height: 70px;
            display: flex;
            align-items: center;
            transition: color 0.3s ease;
        }
        
        .movie-card:hover .card-title {
            color: var(--accent);
        }
        
        .card-text {
            color: #555;
            flex-grow: 1;
            margin-bottom: 20px;
            line-height: 1.6;
            font-size: 0.95rem;
        }
        
        .movie-meta {
            display: flex;
            justify-content: space-between;
            margin-bottom: 15px;
            font-size: 0.9rem;
            color: #777;
            flex-wrap: wrap;
        }
        
        .movie-meta span {
            display: flex;
            align-items: center;
            margin: 3px 0;
        }
        
        .btn-primary {
            background: var(--primary);
            border: none;
            padding: 12px 20px;
            font-weight: 600;
            letter-spacing: 0.5px;
            transition: all 0.3s ease;
            border-radius: 8px;
            display: flex;
            align-items: center;
            justify-content: center;
            width: 100%;
            font-size: 1rem;
            text-transform: uppercase;
            box-shadow: 0 4px 10px rgba(142, 68, 173, 0.3);
            color: white;
        }
        
        .btn-primary:hover {
            background: var(--primary-dark);
            transform: translateY(-3px);
            box-shadow: 0 6px 15px rgba(142, 68, 173, 0.5);
        }
        
        .btn-primary i {
            margin-right: 8px;
        }
        
        .rating {
            position: absolute;
            top: 20px;
            right: 20px;
            background: rgba(231, 76, 60, 0.95);
            color: white;
            width: 50px;
            height: 50px;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: bold;
            font-size: 1.1rem;
            z-index: 10;
            box-shadow: 0 4px 15px rgba(0, 0, 0, 0.25);
            border: 2px solid white;
        }
        
        .filter-bar {
            background: rgba(255, 255, 255, 0.9);
            backdrop-filter: blur(10px);
            border-radius: 12px;
            padding: 20px;
            margin-bottom: 40px;
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
            border: 1px solid rgba(142, 68, 173, 0.2);
        }
        
        .genre-tag {
            display: inline-block;
            background: rgba(255, 255, 255, 0.9);
            color: var(--primary-dark);
            padding: 8px 20px;
            border-radius: 30px;
            margin: 7px 5px;
            font-size: 0.95rem;
            cursor: pointer;
            transition: all 0.3s ease;
            border: 1px solid rgba(142, 68, 173, 0.3);
        }
        
        .genre-tag:hover, .genre-tag.active {
            background: var(--primary);
            color: white;
            transform: translateY(-3px);
            box-shadow: 0 5px 15px rgba(142, 68, 173, 0.3);
            border-color: transparent;
        }
        
        .footer {
            text-align: center;
            margin-top: 50px;
            padding: 30px;
            font-size: 1rem;
            color: var(--dark);
            background: rgba(255, 255, 255, 0.9);
            border-radius: 15px;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
            border: 1px solid rgba(142, 68, 173, 0.1);
        }
        
        .stats-bar {
            background: rgba(255, 255, 255, 0.9);
            border-radius: 12px;
            padding: 25px;
            margin-bottom: 40px;
            display: flex;
            justify-content: space-around;
            flex-wrap: wrap;
            border: 1px solid rgba(142, 68, 173, 0.15);
            box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
        }
        
        .stat-item {
            text-align: center;
            padding: 10px 20px;
        }
        
        .stat-number {
            font-size: 2.8rem;
            font-weight: 800;
            color: var(--primary);
            margin-bottom: 5px;
        }
        
        .stat-label {
            font-size: 1.1rem;
            opacity: 0.9;
            text-transform: uppercase;
            letter-spacing: 1px;
            font-weight: 500;
            color: var(--dark);
        }
        
        .card-img-overlay {
            position: absolute;
            bottom: 0;
            left: 0;
            width: 100%;
            background: linear-gradient(to top, rgba(0, 0, 0, 0.85) 0%, transparent 100%);
            padding: 30px 25px;
            color: white;
            transform: translateY(100%);
            transition: transform 0.4s ease;
        }
        
        .movie-card:hover .card-img-overlay {
            transform: translateY(0);
        }
        
        .overlay-title {
            font-size: 1.8rem;
            font-weight: 700;
            margin-bottom: 15px;
            text-shadow: 0 2px 5px rgba(0, 0, 0, 0.5);
        }
        
        .overlay-meta {
            display: flex;
            flex-wrap: wrap;
        }
        
        .overlay-meta span {
            margin-right: 20px;
            margin-bottom: 10px;
            display: flex;
            align-items: center;
            font-size: 0.95rem;
        }
        
        .fade-in {
            animation: fadeIn 0.8s ease forwards;
        }
        
        @keyframes fadeIn {
            from { opacity: 0; transform: translateY(20px); }
            to { opacity: 1; transform: translateY(0); }
        }
        
        .delay-1 { animation-delay: 0.1s; }
        .delay-2 { animation-delay: 0.2s; }
        .delay-3 { animation-delay: 0.3s; }
        .delay-4 { animation-delay: 0.4s; }
        .delay-5 { animation-delay: 0.5s; }
        .delay-6 { animation-delay: 0.6s; }
        
        .search-results-header {
            text-align: center;
            margin: 20px 0 30px;
            font-size: 1.8rem;
            font-weight: 700;
            color: var(--primary-dark);
            text-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
        }
        
        .no-results {
            text-align: center;
            padding: 50px;
            font-size: 1.2rem;
            color: var(--dark);
            background: rgba(255, 255, 255, 0.9);
            border-radius: 15px;
            margin: 30px 0;
            box-shadow: 0 5px 15px rgba(0, 0, 0, 0.05);
        }
        
        @media (max-width: 768px) {
            .page-header h1 {
                font-size: 2.5rem;
            }
            
            .poster-container {
                height: 300px;
            }
            
            .movie-meta {
                flex-direction: column;
            }
            
            .stat-item {
                flex: 1 0 50%;
                margin-bottom: 15px;
            }
            
            .stat-number {
                font-size: 2rem;
            }
            
            .card-title {
                height: auto;
                min-height: 70px;
            }
            
            .page-header p {
                font-size: 1rem;
            }
        }
        
        /* 添加电影卡片翻转效果 */
        .movie-card-inner {
            transition: transform 0.6s;
            transform-style: preserve-3d;
            position: relative;
            height: 100%;
        }
        
        .movie-card:hover .movie-card-inner {
            transform: rotateY(5deg);
        }
        
        /* 添加搜索建议框 */
        .search-suggestions {
            position: absolute;
            top: 100%;
            left: 0;
            right: 0;
            background: rgba(255, 255, 255, 0.95);
            border-radius: 0 0 15px 15px;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.1);
            z-index: 100;
            max-height: 300px;
            overflow-y: auto;
            display: none;
            border: 1px solid rgba(142, 68, 173, 0.2);
        }
        
        .suggestion-item {
            padding: 12px 25px;
            border-bottom: 1px solid rgba(0, 0, 0, 0.05);
            cursor: pointer;
            transition: all 0.2s;
            color: var(--dark);
            display: flex;
            align-items: center;
        }
        
        .suggestion-item:hover {
            background: rgba(142, 68, 173, 0.1);
            color: var(--primary);
        }
        
        .suggestion-item i {
            margin-right: 10px;
            color: var(--primary);
        }
        
        /* 添加加载动画 */
        .loader {
            display: none;
            text-align: center;
            padding: 30px;
        }
        
        .loader-dot {
            display: inline-block;
            width: 12px;
            height: 12px;
            border-radius: 50%;
            background: var(--primary);
            margin: 0 5px;
            animation: loader 1.4s infinite ease-in-out both;
        }
        
        .loader-dot:nth-child(1) {
            animation-delay: -0.32s;
        }
        
        .loader-dot:nth-child(2) {
            animation-delay: -0.16s;
        }
        
        @keyframes loader {
            0%, 80%, 100% { transform: scale(0); }
            40% { transform: scale(1.0); }
        }
    </style>
</head>
<body>
    <div class="container my-5">
        <!-- 搜索栏 -->
        <div class="search-container fade-in">
            <div class="search-box">
                <i class="fas fa-search"></i>
                <input type="text" id="searchInput" placeholder="搜索电影名称、导演、演员、类型...">
            </div>
            <div class="search-suggestions" id="searchSuggestions"></div>
        </div>
        
        <div class="page-header fade-in">
            <h1><i class="fas fa-film me-3"></i>电影天堂</h1>
            <p class="lead">探索全球最受欢迎的电影作品，每日更新最新最热的影片</p>
        </div>
        
        <!-- 统计数据栏 -->
        <div class="stats-bar fade-in delay-1">
            <div class="stat-item">
                <div class="stat-number" id="totalMovies">0</div>
                <div class="stat-label">电影总数</div>
            </div>
            <div class="stat-item">
                <div class="stat-number" id="totalGenres">0</div>
                <div class="stat-label">电影类型</div>
            </div>
            <div class="stat-item">
                <div class="stat-number" id="avgDuration">0</div>
                <div class="stat-label">平均时长(分钟)</div>
            </div>
            <div class="stat-item">
                <div class="stat-number" id="oldestYear">0</div>
                <div class="stat-label">最老电影年份</div>
            </div>
        </div>
        
        <!-- 过滤栏 -->
        <div class="filter-bar fade-in delay-2">
            <h5 class="mb-3" style="color: var(--primary-dark);"><i class="fas fa-filter me-2"></i>电影类型</h5>
            <div id="genreTags">
                <!-- 类型标签会动态生成 -->
            </div>
        </div>
        
        <!-- 搜索结果标题 -->
        <div class="search-results-header fade-in delay-3" id="resultsHeader" style="display:none;">
            <i class="fas fa-search me-2"></i>搜索结果
        </div>
        
        <!-- 加载动画 -->
        <div class="loader" id="loader">
            <div class="loader-dot"></div>
            <div class="loader-dot"></div>
            <div class="loader-dot"></div>
        </div>
        
        <!-- 电影列表 -->
        <div class="row" id="movieList">
            <!-- 电影卡片会动态加载 -->
        </div>
        
        <div class="footer fade-in delay-6">
            <p>© 2025 电影天堂 | 提供最新最全的电影资讯</p>
            <div class="mt-2">
                <a href="#" class="mx-2" style="color: var(--primary);"><i class="fab fa-weibo"></i></a>
                <a href="#" class="mx-2" style="color: var(--primary);"><i class="fab fa-weixin"></i></a>
                <a href="#" class="mx-2" style="color: var(--primary);"><i class="fab fa-github"></i></a>
            </div>
        </div>
    </div>
    
    <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
    <script>
        // 电影数据 - 包含真实电影海报
        const movies = [
            {
                id: 1,
                title: "霸王别姬",
                director: "陈凯歌",
                actors: "张国荣,张丰毅,巩俐",
                description: "讲述程蝶衣和段小楼两位京剧演员的人生故事，跨越半个世纪的悲欢离合。影片展现了在中国历史变迁中，个人命运与艺术追求的冲突与融合。",
                duration: 171,
                release_date: "1993-01-01",
                genre: "剧情",
                poster_url: "https://images.unsplash.com/photo-1536440136628-849c177e76a1?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=900&ixid=MnwxfDB8MXxyYW5kb218MHx8bW92aWUsZHJhbWF8fHx8fHwxNjg3MjU0NTU4&ixlib=rb-4.0.3&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=600",
                language: "汉语普通话",
                rating: 9.6
            },
            {
                id: 2,
                title: "流浪地球",
                director: "郭帆",
                actors: "吴京,屈楚萧,李光洁",
                description: "太阳即将毁灭，人类在地球表面建造了上万座行星发动机，推动地球离开太阳系。当地球经过木星时，遭遇引力激增危机，人类面临灭顶之灾。",
                duration: 125,
                release_date: "2019-02-05",
                genre: "科幻",
                poster_url: "https://images.unsplash.com/photo-1536440136628-849c177e76a1?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=900&ixid=MnwxfDB8MXxyYW5kb218MHx8bW92aWUsc2NpLWZpfHx8fHx8MTY4NzI1NDYxMA&ixlib=rb-4.0.3&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=600",
                language: "汉语普通话",
                rating: 7.9
            },
            {
                id: 3,
                title: "你好，李焕英",
                director: "贾玲",
                actors: "贾玲,张小斐,沈腾",
                description: "女主角贾晓玲在经历'子欲养而亲不待'的悲痛后，意外穿越回到1981年，与年轻的母亲李焕英相遇，从而展开一段笑中带泪的亲情故事。",
                duration: 128,
                release_date: "2021-02-12",
                genre: "喜剧",
                poster_url: "https://images.unsplash.com/photo-1536440136628-849c177e76a1?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=900&ixid=MnwxfDB8MXxyYW5kb218MHx8bW92aWUsY29tZWR5fHx8fHx8MTY4NzI1NDY0Mw&ixlib=rb-4.0.3&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=600",
                language: "汉语普通话",
                rating: 7.8
            },
            {
                id: 4,
                title: "星际穿越",
                director: "克里斯托弗·诺兰",
                actors: "马修·麦康纳,安妮·海瑟薇",
                description: "在不远的未来，地球气候恶化，农作物相继灭绝。前NASA宇航员库珀被迫离开家人，带领一支探险队穿越虫洞，为人类寻找新的家园。",
                duration: 169,
                release_date: "2014-11-07",
                genre: "科幻",
                poster_url: "https://images.unsplash.com/photo-1536440136628-849c177e76a1?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=900&ixid=MnwxfDB8MXxyYW5kb218MHx8bW92aWUsc3BhY2V8fHx8fHwxNjg3MjU0Njg0&ixlib=rb-4.0.3&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=600",
                language: "英语",
                rating: 9.3
            },
            {
                id: 5,
                title: "肖申克的救赎",
                director: "弗兰克·德拉邦特",
                actors: "蒂姆·罗宾斯,摩根·弗里曼",
                description: "银行家安迪因被诬陷谋杀而入狱。在肖申克监狱中，他凭借智慧与毅力不仅赢得了狱友的尊重，还策划了一场惊天越狱。",
                duration: 142,
                release_date: "1994-09-23",
                genre: "剧情",
                poster_url: "https://images.unsplash.com/photo-1536440136628-849c177e76a1?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=900&ixid=MnwxfDB8MXxyYW5kb218MHx8bW92aWUsZHJhbWF8fHx8fHwxNjg3MjU0NzE3&ixlib=rb-4.0.3&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=600",
                language: "英语",
                rating: 9.7
            },
            {
                id: 6,
                title: "盗梦空间",
                director: "克里斯托弗·诺兰",
                actors: "莱昂纳多·迪卡普里奥,约瑟夫·高登-莱维特",
                description: "盗梦者柯布带领团队潜入他人梦境窃取机密。这一次，他接到一项特殊任务：不是偷取想法，而是在目标人物脑海中植入一个想法。",
                duration: 148,
                release_date: "2010-07-16",
                genre: "科幻",
                poster_url: "https://images.unsplash.com/photo-1536440136628-849c177e76a1?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=900&ixid=MnwxfDB8MXxyYW5kb218MHx8bW92aWUsc2NpLWZpfHx8fHx8MTY4NzI1NDc0NQ&ixlib=rb-4.0.3&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=600",
                language: "英语",
                rating: 9.0
            },
            {
                id: 7,
                title: "阿凡达",
                director: "詹姆斯·卡梅隆",
                actors: "萨姆·沃辛顿,佐伊·索尔达娜",
                description: "在未来世界中，人类为获取潘多拉星球的资源，启动了阿凡达计划。前海军陆战队员杰克通过基因工程制造的阿凡达身体进入潘多拉星球。",
                duration: 162,
                release_date: "2009-12-18",
                genre: "科幻",
                poster_url: "https://images.unsplash.com/photo-1536440136628-849c177e76a1?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=900&ixid=MnwxfDB8MXxyYW5kb218MHx8bW92aWUsYXZhdGFyfHx8fHx8MTY4NzI1NDc4Ng&ixlib=rb-4.0.3&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=600",
                language: "英语",
                rating: 8.7
            },
            {
                id: 8,
                title: "让子弹飞",
                director: "姜文",
                actors: "姜文,葛优,周润发",
                description: "民国年间，花钱捐得县长的马邦德携妻及随从走马上任，途中遭遇劫匪张麻子一伙伏击。为保命，马邦德谎称自己是师爷，与张麻子踏上了进城当官的冒险旅程。",
                duration: 132,
                release_date: "2010-12-16",
                genre: "喜剧",
                poster_url: "https://images.unsplash.com/photo-1536440136628-849c177e76a1?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=900&ixid=MnwxfDB8MXxyYW5kb218MHx8bW92aWUsY2hpbmVzZXxlbnwwfHx8fHwxNjg3MjU0ODE2&ixlib=rb-4.0.3&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=600",
                language: "汉语普通话",
                rating: 8.8
            },
            {
                id: 9,
                title: "千与千寻",
                director: "宫崎骏",
                actors: "柊瑠美,入野自由",
                description: "10岁的少女千寻与父母搬往新家，途中误入一个神秘隧道，进入了一个不可思议的小镇。千寻的父母因为贪吃变成了猪，千寻必须在这个神灵世界中工作以拯救父母。",
                duration: 125,
                release_date: "2001-07-20",
                genre: "动画",
                poster_url: "https://images.unsplash.com/photo-1536440136628-849c177e76a1?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=900&ixid=MnwxfDB8MXxyYW5kb218MHx8bW92aWUsYW5pbWF0aW9ufHx8fHx8MTY4NzI1NDg0Mw&ixlib=rb-4.0.3&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=600",
                language: "日语",
                rating: 9.3
            },
            {
                id: 10,
                title: "泰坦尼克号",
                director: "詹姆斯·卡梅隆",
                actors: "莱昂纳多·迪卡普里奥,凯特·温丝莱特",
                description: "1912年泰坦尼克号邮轮在其处女航时触礁冰山而沉没，讲述了处于不同阶层的两个人——穷画家杰克和贵族女露丝抛弃世俗的偏见坠入爱河，最终杰克把生存的机会让给了露丝的感人故事。",
                duration: 194,
                release_date: "1997-12-19",
                genre: "爱情",
                poster_url: "https://images.unsplash.com/photo-1536440136628-849c177e76a1?crop=entropy&cs=tinysrgb&fit=crop&fm=jpg&h=900&ixid=MnwxfDB8MXxyYW5kb218MHx8bW92aWUsbG92ZXxlbnwwfHx8fHwxNjg3MjU0ODc0&ixlib=rb-4.0.3&q=80&utm_campaign=api-credit&utm_medium=referral&utm_source=unsplash_source&w=600",
                language: "英语",
                rating: 9.4
            }
        ];

        // 页面加载完成后初始化
        document.addEventListener('DOMContentLoaded', function() {
            // 渲染统计数据
            renderStatistics();
            
            // 渲染类型标签
            renderGenreTags();
            
            // 渲染电影列表
            renderMovieList();
            
            // 添加搜索功能
            setupSearch();
        });
        
        // 渲染统计数据
        function renderStatistics() {
            // 计算统计数据
            const totalMovies = movies.length;
            const genres = [...new Set(movies.map(movie => movie.genre))];
            const totalGenres = genres.length;
            const totalDuration = movies.reduce((sum, movie) => sum + movie.duration, 0);
            const avgDuration = Math.round(totalDuration / totalMovies);
            const oldestYear = Math.min(...movies.map(movie => new Date(movie.release_date).getFullYear()));
            
            // 更新DOM
            document.getElementById('totalMovies').textContent = totalMovies;
            document.getElementById('totalGenres').textContent = totalGenres;
            document.getElementById('avgDuration').textContent = avgDuration;
            document.getElementById('oldestYear').textContent = oldestYear;
        }
        
        // 渲染类型标签
        function renderGenreTags() {
            const genreTagsContainer = document.getElementById('genreTags');
            const genres = [...new Set(movies.map(movie => movie.genre))];
            
            // 添加"全部"标签
            genreTagsContainer.innerHTML = `<span class="genre-tag active" data-genre="all">全部</span>`;
            
            // 添加各类型标签
            genres.forEach(genre => {
                genreTagsContainer.innerHTML += `<span class="genre-tag" data-genre="${genre}">${genre}</span>`;
            });
            
            // 添加标签点击事件
            document.querySelectorAll('.genre-tag').forEach(tag => {
                tag.addEventListener('click', function() {
                    // 更新活动标签
                    document.querySelectorAll('.genre-tag').forEach(t => t.classList.remove('active'));
                    this.classList.add('active');
                    
                    // 过滤电影
                    const genre = this.getAttribute('data-genre');
                    renderMovieList(genre === 'all' ? null : genre);
                });
            });
        }
        
        // 渲染电影列表
        function renderMovieList(filterGenre = null, searchTerm = null) {
            const movieList = document.getElementById('movieList');
            const loader = document.getElementById('loader');
            const resultsHeader = document.getElementById('resultsHeader');
            
            // 显示加载动画
            movieList.innerHTML = '';
            loader.style.display = 'block';
            
            // 延迟显示结果，模拟加载过程
            setTimeout(() => {
                loader.style.display = 'none';
                
                // 过滤电影
                let filteredMovies = movies;
                
                if (filterGenre && filterGenre !== 'all') {
                    filteredMovies = filteredMovies.filter(movie => movie.genre === filterGenre);
                }
                
                if (searchTerm) {
                    resultsHeader.style.display = 'block';
                    const term = searchTerm.toLowerCase();
                    filteredMovies = filteredMovies.filter(movie => 
                        movie.title.toLowerCase().includes(term) ||
                        movie.director.toLowerCase().includes(term) ||
                        movie.actors.toLowerCase().includes(term) ||
                        movie.genre.toLowerCase().includes(term) ||
                        movie.description.toLowerCase().includes(term)
                    );
                } else {
                    resultsHeader.style.display = 'none';
                }
                
                // 检查是否有结果
                if (filteredMovies.length === 0) {
                    movieList.innerHTML = `
                        <div class="col-12">
                            <div class="no-results">
                                <i class="fas fa-search fa-3x mb-3" style="color: var(--primary);"></i>
                                <h3>未找到匹配的电影</h3>
                                <p>请尝试使用其他关键字搜索</p>
                            </div>
                        </div>
                    `;
                    return;
                }
                
                // 渲染电影卡片
                movieList.innerHTML = '';
                filteredMovies.forEach((movie, index) => {
                    const delayClass = `delay-${index % 6 + 1}`;
                    const movieCard = createMovieCard(movie, delayClass);
                    movieList.innerHTML += movieCard;
                });
            }, 600);
        }
        
        // 创建电影卡片HTML
        function createMovieCard(movie, delayClass) {
            // 从上映日期中提取年份
            const releaseYear = new Date(movie.release_date).getFullYear();
            
            return `
                <div class="col-lg-4 col-md-6 mb-4">
                    <div class="movie-card fade-in ${delayClass}">
                        <div class="poster-container">
                            <img src="${movie.poster_url}" class="movie-poster" alt="${movie.title}海报">
                            <div class="rating">${movie.rating}</div>
                            <div class="card-img-overlay">
                                <div class="overlay-title">${movie.title}</div>
                                <div class="overlay-meta">
                                    <span><i class="fas fa-user me-2"></i> ${movie.director}</span>
                                    <span><i class="fas fa-calendar me-2"></i> ${releaseYear}</span>
                                    <span><i class="fas fa-clock me-2"></i> ${movie.duration}分钟</span>
                                    <span><i class="fas fa-tag me-2"></i> ${movie.genre}</span>
                                </div>
                            </div>
                        </div>
                        <div class="card-body">
                            <h5 class="card-title">${movie.title}</h5>
                            <div class="movie-meta">
                                <span><i class="fas fa-user me-2"></i> ${movie.director}</span>
                                <span><i class="fas fa-calendar me-2"></i> ${releaseYear}</span>
                                <span><i class="fas fa-clock me-2"></i> ${movie.duration}分钟</span>
                                <span><i class="fas fa-tag me-2"></i> ${movie.genre}</span>
                                <span><i class="fas fa-globe me-2"></i> ${movie.language}</span>
                            </div>
                            <p class="card-text">${movie.description}</p>
                           <a href="/movie/${movie.id}" class="btn btn-primary"><i class="fas fa-info-circle"></i> 查看详情</a>
                        </div>
                    </div>
                </div>
            `;
        }
        
        // 设置搜索功能
        function setupSearch() {
            const searchInput = document.getElementById('searchInput');
            const suggestionsContainer = document.getElementById('searchSuggestions');
            let searchTimeout;
            
            // 输入事件处理
            searchInput.addEventListener('input', function() {
                const term = this.value.trim().toLowerCase();
                
                // 清除之前的超时
                clearTimeout(searchTimeout);
                
                // 显示建议
                if (term.length > 0) {
                    showSuggestions(term);
                    suggestionsContainer.style.display = 'block';
                } else {
                    suggestionsContainer.style.display = 'none';
                    // 如果没有搜索词，显示所有电影
                    renderMovieList();
                }
                
                // 设置搜索延迟
                searchTimeout = setTimeout(() => {
                    if (term.length > 0) {
                        renderMovieList(null, term);
                    }
                }, 500);
            });
            
            // 点击外部关闭建议框
            document.addEventListener('click', function(e) {
                if (!searchInput.contains(e.target) && !suggestionsContainer.contains(e.target)) {
                    suggestionsContainer.style.display = 'none';
                }
            });
        }
        
        // 显示搜索建议
        function showSuggestions(term) {
            const suggestionsContainer = document.getElementById('searchSuggestions');
            suggestionsContainer.innerHTML = '';
            
            // 获取匹配的电影
            const matchedMovies = movies.filter(movie => 
                movie.title.toLowerCase().includes(term) ||
                movie.director.toLowerCase().includes(term) ||
                movie.actors.toLowerCase().includes(term) ||
                movie.genre.toLowerCase().includes(term)
            );
            
            // 添加建议
            if (matchedMovies.length > 0) {
                matchedMovies.slice(0, 5).forEach(movie => {
                    const item = document.createElement('div');
                    item.className = 'suggestion-item';
                    item.innerHTML = `<i class="fas fa-film"></i> ${movie.title} (${movie.director})`;
                    
                    item.addEventListener('click', () => {
                        searchInput.value = movie.title;
                        suggestionsContainer.style.display = 'none';
                        renderMovieList(null, movie.title);
                    });
                    
                    suggestionsContainer.appendChild(item);
                });
            } else {
                const item = document.createElement('div');
                item.className = 'suggestion-item';
                item.innerHTML = `<i class="fas fa-info-circle"></i> 没有找到匹配的电影`;
                suggestionsContainer.appendChild(item);
            }
            
            // 添加"查看所有结果"选项
            const showAll = document.createElement('div');
            showAll.className = 'suggestion-item';
            showAll.innerHTML = `<i class="fas fa-search"></i> 查看所有结果`;
            showAll.style.fontWeight = 'bold';
            showAll.style.background = 'rgba(142, 68, 173, 0.1)';
            
            showAll.addEventListener('click', () => {
                renderMovieList(null, term);
                suggestionsContainer.style.display = 'none';
            });
            
            suggestionsContainer.appendChild(showAll);
        }
    </script>
</body>
</html>